<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
    public function login(){
    	layout(false);
		$this->display();
    }
	public function do_login(){
		$rules = array(
			array('username','require','账户名必须！'),
			array('password','require','密码必须！'),
		);
		$admin_model = M("admin");
		if (!$admin_model->validate($rules)->create()){
			$this->error($admin_model->getError());
		}else{
			$admin = M("admin")->where(array('username' => I('post.username'),'password' => md5(I('post.password'))))->find();
			if (!$admin) {
				$this->error('账户名和密码不正确！');
			}
			$_SESSION['admin_is_login']=true;
			$_SESSION['admin_name']=$admin['username'];
			$_SESSION['admin_id']=$admin['id'];
			$this->redirect('Admin/index/index');
		}
	}
    public function logout(){
    	session_destroy();
		$this->success('退出成功！',U('Admin/auth/login'));
    }
}